<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <link rel="icon" type="image/svg+xml" href="./favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>学法减分题库管理系统</title>
  <script>
    console.log('初始化子目录部署应用...');
    // 确保基本路径正确
    window.__BASE_PATH = '/xuefa/';
    
    // 自动添加哈希
    if(!window.location.hash) window.location.hash = "#/";
    
    // 资源路径修正函数
    function fixPath(path) {
      if (path.startsWith('./')) {
        return window.__BASE_PATH + path.substring(2);
      } else if (path.startsWith('/')) {
        return window.__BASE_PATH + path.substring(1);
      }
      return window.__BASE_PATH + path;
    }
    
    // 记录加载错误
    window.addEventListener('error', function(e) {
      if (e.target && (e.target.tagName === 'SCRIPT' || e.target.tagName === 'LINK')) {
        console.error('资源加载错误:', e.target.src || e.target.href);
        
        // 尝试修复路径
        var originalSrc = e.target.src || e.target.href;
        if (originalSrc && !originalSrc.includes(window.__BASE_PATH)) {
          var newSrc = fixPath(originalSrc.substring(originalSrc.lastIndexOf('/') + 1));
          console.log('尝试修复路径:', originalSrc, '->', newSrc);
          
          if (e.target.tagName === 'SCRIPT') {
            e.target.src = newSrc;
          } else {
            e.target.href = newSrc;
          }
        }
      }
    }, true);
    
    // 设置最大超时，确保应用最终能够运行
    setTimeout(function() {
      var app = document.getElementById('app');
      if (!app || !app.hasChildNodes()) {
        console.warn('应用加载超时，尝试恢复...');
        window.location.reload();
      }
    }, 10000);
  </script>
</head>
<body>
  <div id="app"></div>
  <script>
    // 修正主脚本路径
    document.write('<script type="module" src="' + window.__BASE_PATH + 'static/js/main-' + (window.__MAIN_HASH || '') + '.js"><\/script>');
  </script>
  <noscript>
    <strong>很抱歉，如果不启用JavaScript，学法减分题库系统将无法正常工作。请启用它继续。</strong>
  </noscript>
</body>
</html> 